home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 2 / Atari Mega Archive CD - Volume 2.iso / linux / src / atalnx_3.lzh / atari-linux-0.01pl3 / atari / joystick.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-05  |  2.5 KB  |  112 lines

  1. /*
  2.  * Atari Joystick Driver for Linux
  3.  * by Robert de Vries (robert@and.nl) 19Jul93
  4.  */
  5.  
  6. #include <linux/sched.h>
  7. #include <linux/errno.h>
  8. #include <linux/atarikb.h>
  9. #include <linux/atari_joystick.h>
  10. #include <asm/segment.h>
  11.  
  12. static struct joystick_status joystick[2];
  13.  
  14. void joystick_interrupt(char *buf)
  15. {
  16.     int j;
  17. /*    ikbd_joystick_disable(); */
  18.  
  19.     j = buf[0] & 0x1;
  20.     joystick[j].dir   = buf[1] & 0xF;
  21.     joystick[j].fire  = (buf[1] & 0x80) >> 7;
  22.     joystick[j].ready = 1;
  23.     wake_up_interruptible(&joystick[j].wait);
  24.  
  25. /*    ikbd_joystick_event_on(); */
  26. }
  27.  
  28. static void release_joystick(struct inode *inode, struct file *file)
  29. {
  30.     int minor = MINOR(inode->i_rdev);
  31.  
  32.     joystick[minor].active = 0;
  33.     joystick[minor].ready = 0;
  34.  
  35.     if ((joystick[0].active == 0) && (joystick[1].active == 0))
  36.     ikbd_joystick_disable();
  37. }
  38.  
  39. static int open_joystick(struct inode *inode, struct file *file)
  40. {
  41.     int minor = MINOR(inode->i_rdev);
  42.  
  43.     if (minor > 1)
  44.     return -ENODEV;
  45.     if (joystick[minor].active)
  46.     return -EBUSY;
  47.     joystick[minor].active = 1;
  48.     joystick[minor].ready = 0;
  49.     ikbd_joystick_event_on();
  50.     return 0;
  51. }
  52.  
  53. static int write_joystick(struct inode *inode, struct file *file, char *buffer, int count)
  54. {
  55.     return -EINVAL;
  56. }
  57.  
  58. static int read_joystick(struct inode *inode, struct file *file, char *buffer, int count)
  59. {
  60.     int minor = MINOR(inode->i_rdev);
  61.     int i;
  62.  
  63.     if (count < 2)
  64.     return -EINVAL;
  65.     if (!joystick[minor].ready)
  66.     return -EAGAIN;
  67.     put_fs_byte(joystick[minor].fire, buffer++);
  68.     put_fs_byte(joystick[minor].dir, buffer++);
  69.     for (i = 0; i < count; i++)
  70.     put_fs_byte(0, buffer++);
  71.     joystick[minor].ready = 0;
  72.  
  73.     return i;
  74. }
  75.  
  76. static int joystick_select(struct inode *inode, struct file *file, int sel_type, select_table *wait)
  77. {
  78.     int minor = MINOR(inode->i_rdev);
  79.  
  80.     if (sel_type != SEL_IN)
  81.     return 0;
  82.     if (joystick[minor].ready)
  83.     return 1;
  84.     select_wait(&joystick[minor].wait, wait);
  85.     return 0;
  86. }
  87.  
  88. struct file_operations joystick_fops = {
  89.     NULL,        /* joystick_seek */
  90.     read_joystick,
  91.     write_joystick,
  92.     NULL,        /* joystick_readdir */
  93.     joystick_select,
  94.     NULL,        /* joystick_ioctl */
  95.     NULL,        /* joystick_mmap */
  96.     open_joystick,
  97.     release_joystick
  98. };
  99.  
  100. unsigned long joystick_init(unsigned long kmem_start)
  101. {
  102.     joystick[0].active = joystick[1].active = 0;
  103.     joystick[0].ready = joystick[1].ready = 0;
  104.     joystick[0].wait = joystick[1].wait = NULL;
  105.  
  106.     if (register_chrdev(11, "joystick", &joystick_fops))
  107.     printk("unable to get major 11 for joystick devices\n");
  108.     printk("Atari joystick driver installed.\n");
  109.  
  110.     return kmem_start;
  111. }
  112.